import json
import os
import logging


class Definition():
	def __init__(self, file):
		file = open(file, 'r')
		text = file.read()
		file.close()
		self.content = json.loads(text)

	def close(self):
		pass

	@classmethod
	def read_folder(cls, folder):
		files = os.listdir(folder)
		definitions = []

		for file in files:
			try:
				definition = cls(folder + '/' + file)
				definitions.append(definition)
			except Exception as error:
				logging.error(error)

		return definitions

	def get_text(self):
		return self.content['name']
